#include "shaderclass.h"

ShaderClass::ShaderClass() : m_vertexShader(0),m_pixelShader(0),m_hullShader(0),m_domainShader(0),m_layout(0), m_matrixBuffer(0)
{
}

ShaderClass::~ShaderClass()
{
	ShutdownShader();
}

void ShaderClass::ShutdownShader()
{
	if(m_matrixBuffer)
	{
		m_matrixBuffer->Release();
		m_matrixBuffer = 0;
	}

	if(m_layout)
	{
		m_layout->Release();
		m_layout = 0;
	}

	if(m_pixelShader)
	{
		m_pixelShader->Release();
		m_pixelShader = 0;
	}

	if(m_vertexShader)
	{
		m_vertexShader->Release();
		m_vertexShader = 0;
	}

	if(m_hullShader)
	{
		m_hullShader->Release();
		m_hullShader = 0;
	}

	if(m_domainShader)
	{
		m_domainShader->Release();
		m_domainShader = 0;
	}
}

void ShaderClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage)
{
	OutputDebugStringA( (char*)errorMessage->GetBufferPointer() );
	MessageBoxA(0, (char*)errorMessage->GetBufferPointer(), 0, 0);
}

void ShaderClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount)
{
	deviceContext->IASetInputLayout(m_layout);

	if (m_vertexShader)
	{
		deviceContext->VSSetShader(m_vertexShader, NULL, 0);
	}

	if (m_pixelShader)
	{
		deviceContext->PSSetShader(m_pixelShader, NULL, 0);
	}

	if (m_domainShader)
	{
		deviceContext->DSSetShader(m_domainShader, NULL, 0);
	}

	if (m_hullShader)
	{
		deviceContext->HSSetShader(m_hullShader, NULL, 0);
	}

	deviceContext->DrawIndexed(indexCount, 0, 0);
}